package jp.co.sharp.android.parents.kidsguard.common;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import jp.co.sharp.android.parents.kidsguard.R;

public class MimamoriPhoneDlg extends Dialog {

    private OnConfirmSetListener mOnConfirmSetListener;
    private OnCancelSetListener mOnCancelSetListener;
    private OnImadocoSetListener mOnImadocoSetListener;
    private String mDlgMessage;
    private MimamoriPhoneDlg mMimamoriConfirmDlg;
    private String mConfirmBtn;
    private String mCancelBtn;
    private String mMacId;

    public MimamoriPhoneDlg(@NonNull Context context, String pDlgMessage, String pConfirmBtn, String pCancelBtn, String pMacId) {
        super(context);
        this.mDlgMessage = pDlgMessage;
        this.mMimamoriConfirmDlg = this;
        this.mConfirmBtn = pConfirmBtn;
        this.mCancelBtn = pCancelBtn;
        this.mMacId = pMacId;
    }

    public MimamoriPhoneDlg(@NonNull Context context, int themeResId, String pDlgMessage, String pConfirmBtn, String pCancelBtn, String pMacId) {
        super(context, themeResId);
        this.mDlgMessage = pDlgMessage;
        this.mMimamoriConfirmDlg = this;
        this.mConfirmBtn = pConfirmBtn;
        this.mCancelBtn = pCancelBtn;
        this.mMacId = pMacId;
    }

    protected MimamoriPhoneDlg(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener, String pDlgMessage, String pConfirmBtn, String pCancelBtn, String pMacId) {
        super(context, cancelable, cancelListener);
        this.mDlgMessage = pDlgMessage;
        this.mMimamoriConfirmDlg = this;
        this.mConfirmBtn = pConfirmBtn;
        this.mCancelBtn = pCancelBtn;
        this.mMacId = pMacId;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dlg_mimamori_phone);

        initDlg();
    }

    private void initDlg() {
        TextView textView = (TextView)findViewById(R.id.dlgMsg);
        textView.setText(Html.fromHtml(mDlgMessage));

        Button cancelBtn = (Button)findViewById(R.id.cancelBtn);
        cancelBtn.setText(mCancelBtn);
        cancelBtn.setOnClickListener(new ListenerCancel());

        Button confirmBtn = (Button)findViewById(R.id.confirmBtn);
        confirmBtn.setText(mConfirmBtn);
        confirmBtn.setOnClickListener(new ListenerOK());

        TextView openBrowserTv = (TextView)findViewById(R.id.openBrowserTv);
        textView.setOnClickListener(new ListenerImadoco());
    }

    /**
     *
     */
    public interface OnConfirmSetListener {
        void onOperateSet(String pMacId);
    }

    /*
     * 对外公开方法让Activity实现
     */
    public void setOnConfirmSetListener(OnConfirmSetListener callBack) {
        mOnConfirmSetListener = callBack;
    }

    class ListenerOK implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (mOnConfirmSetListener != null) {
                mOnConfirmSetListener.onOperateSet(mMacId);
            }
        }
    }

    /**
     *
     */
    public interface OnCancelSetListener {
        void onOperateSet(String pMacId);
    }
    /*
     * 对外公开方法让Activity实现
     */
    public void setOnCancelSetListener(OnCancelSetListener callBack) {
        mOnCancelSetListener = callBack;
    }

    class ListenerCancel implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (mOnCancelSetListener != null) {
                mOnCancelSetListener.onOperateSet(mMacId);
            }
        }
    }

    /**
     *
     */
    public interface OnImadocoSetListener {
        void onOperateSet(String pMacId);
    }

    /*
     * 对外公开方法让Activity实现
     */
    public void setOnImadocoSetListener(OnImadocoSetListener callBack) {
        mOnImadocoSetListener = callBack;
    }

    class ListenerImadoco implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (mOnImadocoSetListener != null) {
                mOnImadocoSetListener.onOperateSet(mMacId);
            }
        }
    }
}
